﻿using Desktop.Interfaces;
using System;
using System.Runtime.Serialization;

namespace Desktop.Library
{
    [Serializable()]
    public class Character : ContentItem<Character>
    {
        #region Variables

        private string _name;
        private DateTime _birthDate;
        private string _biography;

        #endregion

        #region Constructors

        public Character()
            : base()
        {
            Name = string.Empty;
            BirthDate = DateTime.Now;
            Biography = string.Empty;
        }

        public Character(Character character)
            : base(character)
        {
            if (character == null)
            {
                return;
            }
            Name = character.Name;
            BirthDate = character.BirthDate;
            Biography = character.Biography;
        }

        public Character(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            Name = info.GetString("Name");
            BirthDate = info.GetDateTime("BirthDate");
            Biography = info.GetString("Biography");
        }

        #endregion

        #region Properties

        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                if (_name != value)
                {
                    PropertyHasChanged("Name");

                }
                _name = value;
            }
        }

        public DateTime BirthDate
        {
            get
            {
                return _birthDate;
            }
            set
            {
                if (_birthDate != value)
                {
                    PropertyHasChanged("BirthDate");

                }
                _birthDate = value;
            }
        }

        public string Biography
        {
            get
            {
                return _biography;
            }
            set
            {
                if (_biography != value)
                {
                    PropertyHasChanged("Biography");

                }
                _biography = value;
            }
        }

        #endregion

        #region Methods

        public override string ToString()
        {
            return Name;
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Name", Name);
            info.AddValue("BirthDate", BirthDate);
            info.AddValue("Biography", Biography);
            base.GetObjectData(info, context);
        }

        #endregion
    }
}